<?php

class Admin_Form_Atendimentonap extends Zend_Form
{
    public function init() {
   	    
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;
        $urlbase = $front->getBaseUrl();
        
        $id = $front->getRequest()->getParam('id', 0);
        $alu_id = $front->getRequest()->getParam('alu_id', 0);
        
        $url .= '/aluno/alu_id/'.$alu_id;
        
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        
        $this->setName('form');
        
        if($id > 0){
           $query = 'SELECT SQL_CACHE * FROM ATENDIMENTO_NAP WHERE ATP_ID = ' . $id;
           $data = $db->fetchRow($query);
        }
        
        $el = new Zend_Form_Element_Hidden('ATP_ID',array('disableLoadDefaultDecorators' =>true));
        $el->addDecorators(array(array('ViewHelper'),array('Errors')))
            ->addFilter('Int');
        $this->addElement($el);
       
        
        $arr = array(''=> 'Nenhum');
        $query = 'SELECT SQL_CACHE TAH_ID,TAH_NOM FROM TIPO_ATENDIMENTONAP ORDER BY TAH_NOM';
        $result = $db->fetchAll($query);
        foreach($result as $row) $arr[$row['TAH_ID']] = $row['TAH_NOM'];
        
        $el = new Zend_Form_Element_Select('TAH_ID',array('onchange' => ''));
        $el->setLabel('Tipo')->setRequired(true);
        $el->addMultiOptions($arr);
        $el->setAttrib('required','');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Textarea('ATP_TXT');
        $el->setLabel('Atendimento')->setRequired(true);
        $el->setAttrib('class','txt_grd');
        $el->setAttrib('required','');
        $this->addElement($el);
        
        if($id > 0){
            $el = new Zend_Form_Element_Checkbox('ATP_STA',array('checked'=>'checked'));
            $el->setLabel('Status');
            $this->addElement($el);
        }
        
        $btn = new Zend_Form_Element_Submit('Salvar',array('disableLoadDefaultDecorators' =>true));
        $btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setLabel('Salvar');
        $btn->setAttrib('id', 'submitbutton');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);
        
        $btn = new Zend_Form_Element_Button('Cancelar',array('disableLoadDefaultDecorators' =>true));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="'.$url.'" class="btn-frm">Voltar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-frm');
        $this->addElement($btn);
        
        
    }

}

